from time import sleep
from unittest import TestCase

from selenium import webdriver

from ecshops.po.GoodsListPage import GoodsListPage
from ecshops.po.LoginPage import LoginPage


class TestGoodsList(TestCase):


    def test_search_by_keyword(self):
        driver = webdriver.Chrome()
        login = LoginPage(driver)
        login.open('http://192.168.20.244/ecshop/admin/privilege.php?act=login')
        login.input_username()
        login.input_password()
        login.click_login_button()

        goods = GoodsListPage(driver)
        goods.into_menu_frame()
        goods.click_goods_link()
        goods.out_menu_frame()
        goods.into_main_frame()
        goods.input_keyword()
        goods.click_search_button()

        sleep(2)

    def test_search_by_keyword2type(self):
        driver = webdriver.Chrome()
        login = LoginPage(driver)
        login.open('http://192.168.20.244/ecshop/admin/privilege.php?act=login')
        login.input_username()
        login.input_password()
        login.click_login_button()

        goods = GoodsListPage(driver)
        goods.into_menu_frame()
        goods.click_goods_link()
        goods.out_menu_frame()
        goods.into_main_frame()

        goods.select_by_type()
        goods.input_keyword()
        goods.click_search_button()

        sleep(10)

    def test_add_goods(self):
        driver = webdriver.Chrome()
        login = LoginPage(driver)
        login.open('http://192.168.20.244/ecshop/admin/privilege.php?act=login')
        login.input_username()
        login.input_password()
        login.click_login_button()

        goods = GoodsListPage(driver)
        goods.into_menu_frame()
        goods.click_add_goods_link()
        goods.out_menu_frame()
        goods.into_main_frame()
        goods.input_goods_name()
        goods.select_category()
        goods.click_submit()

    def test_is_not_sale(self):
        # 下架
        driver = webdriver.Chrome()
        login = LoginPage(driver)
        login.open('http://192.168.20.244/ecshop/admin/privilege.php?act=login')
        login.input_username()
        login.input_password()
        login.click_login_button()

        goods = GoodsListPage(driver)
        goods.into_menu_frame()
        goods.click_goods_link()
        goods.out_menu_frame()
        goods.into_main_frame()
        goods.click_is_not_sales()
        sleep(10)
